/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import org.aswing.Image;

import fever.exception.IllegalAccessException;

import flash.filters.DropShadowFilter;

/**
 * Abstract class to define basic behaviour for all cursors implementation.
 * 
 * @author Romain Ecarnot
 */
class fvaswing.components.cursors.FvAbstractCursor implements Image
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _target : MovieClip;
	private var _container : MovieClip;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Returns the image's width.
	 */
	public function getImageWidth() : Number
	{
		return _target._width;
	}
	
	/**
	 * Returns the image's height.
	 */
	public function getImageHeight() : Number
	{
		return _target._height;
	}
	
	/**
	 * Paints the image to a specified movieclip at point(x, y)
	 */
	public function paintImage( target : MovieClip, x : Number, y : Number ) : Void
	{
		_target = target;
		
		_container.removeMovieClip();
		_container = _target.createEmptyMovieClip( '__container__', 1 );
		
		repaint();
	}
	
	/**
	 * Concrete drawing implementation.
	 * 
	 * @throws Error if not be override by cursor subclasses.
	 */
	public function repaint() : Void
	{
		throw new IllegalAccessException( 'Must be override by cursor subclasses' );
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	private function FvAbstractCursor()
	{
		
	}
	
	/**
	 * If you work with Flash Player 8 and above, apply SoftShadow Filter
	 */
	private function _applyFilter() : Void
	{
		var filter : DropShadowFilter = new DropShadowFilter( 1, 45, 0x000000, 0.4, 4, 4, 1, 2 );
		var tmp : Array = _container.filters;
		tmp.push( filter );
		_container.filters = tmp;
	}
}